<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom:0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-select size="small" clearable style="width:200px;" v-model="filters.status" placeholder="请选择状态">
            <!-- <el-option label="全部状态"  value="-1"  ></el-option> -->
            <el-option label="有效" value="1"></el-option>
            <el-option label="已停止" value="0"></el-option>
            <el-option label="待审批有效" value="2"></el-option>
            <el-option label="待审批停止" value="3"></el-option>
            <el-option label="待审批预算" value="4"></el-option>
            <el-option label="审批未通过" value="5"></el-option>
            <el-option label="到期结束" value="6"></el-option>
            <el-option label="未及时审批" value="7"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input size="small" style="width:200px;" v-model.trim="filters.activityName" placeholder="活动名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input size="small" style="width:200px;" v-model.trim="filters.activityCode" placeholder="活动编码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-tooltip class="item" effect="dark" content="计划起止日期" placement="top">
            <el-date-picker size="small" style="width:200px;" v-model="filters.planTime" type="daterange" align="left" placeholder="选择计划起止日期范围">
            </el-date-picker>
          </el-tooltip>
        </el-form-item>
        <el-form-item style="float:right;">
          <el-button size="small" type="primary" icon="plus" v-show="activityAdd" :disabled="configUser()" @click="handleAdd">新增</el-button>
        </el-form-item>
        <el-form-item style="float:right;">
          <el-button size="small" type="primary" icon="search" v-show="activityQuery" v-on:click="getactive(true)">查询</el-button>
        </el-form-item>

        <!-- <el-form-item>
              <el-button size="small" type="primary"  icon="upload2" @click="exportExcels">导出</el-button>
            </el-form-item> -->
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="Logs" stripe border :height="winHeight-188" highlight-current-row v-loading="listLoading"  style="width: 100%;" :cell-style="{height:'10px',color:'#ccc'}">
      <!-- <el-table-column type="selection" width="55">
      </el-table-column> -->
      <!-- <el-table-column prop="serialNo" label="序号" width="120" sortable>
      </el-table-column> -->
      <el-table-column prop="id" align="center" label="活动ID" width="80">
        <!-- <el-tooltip class="item" effect="dark" :content="scope.row.shareId" placement="top"> -->
        <!-- <template scope="scope">
            <span style="height:20px;">{{scope.row.shareId}}</span>
          </template> -->
        <!-- </el-tooltip> -->
      </el-table-column>
      <el-table-column prop="activityName" align="center" label="活动名称" min-width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="activityCode" align="center" label="活动编码" min-width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="activityType" align="center" label="活动类型" min-width="120" show-overflow-tooltip :formatter="formatTypes">
      </el-table-column>
      <el-table-column prop="sumBudget" align="center" label="总预算" min-width="120">
      </el-table-column>
      <el-table-column prop="balanceBudget" align="center" label="余额" width="120">
      </el-table-column>
      <el-table-column prop="warnBalance" align="center" label="预警余额" width="120">
      </el-table-column>
      <el-table-column prop="status" align="center" label="状态" min-width="140" :formatter="formatStatus">
      </el-table-column>
      <el-table-column prop="planStartTime" align="center" label="计划开始时间" min-width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="planEndTime" align="center" label="计划结束时间" min-width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed='right' width="200">
        <template scope="scope">
          <!-- <el-button size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button> -->
          <el-col :xs="8" :sm="8" :md="8" :lg="8">
            <el-button size="small" v-show="activityDetail" @click="handleDetail(scope.$index, scope.row)">详情</el-button>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8">
            <el-button type="warning" size="small" :disabled="configUser()" v-show="IsExamineOther(scope.$index, scope.row)" @click="handleStop(scope.$index, scope.row)">停止</el-button>
            <el-button type="danger" size="small" style="margin-left:0px;" :disabled="ApproveUser(scope.$index, scope.row)" v-show="IsExamines(scope.$index, scope.row)" @click="handleExamine(scope.$index, scope.row)">审批</el-button>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8">
            <el-button type="primary" size="small" :disabled="configUser()" v-show="IsExamineOtherE(scope.$index, scope.row)" @click="handleAddbudget(scope.$index, scope.row)">预算</el-button>
          </el-col>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <!-- <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button> -->

      <el-pagination style="float:right" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[10, 20, 40, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-col>

    <!--新增界面-->
    <el-dialog title="新增活动发放规则" v-model="addFormVisible" :close-on-click-modal="false">
      <el-form label-width="125px" :model="addForm" :rules="addFormRules" ref="addForm">
        <el-row>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="活动名称:" prop="activityName">
              <el-input v-model="addForm.activityName" style="width:100%;" auto-complete="off" placeholder="请输入活动名称">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="活动类型:" prop="activityType">
              <el-select v-model="addForm.activityType" @change="activityTypeChange(addForm.activityType)" class="otherWidth" placeholder="请选择活动类型">
                <el-option label="出单活动" value="1"></el-option>
                <el-option label="使用推广" value="2"></el-option>
                <el-option label="抽奖活动" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="触发类型:" prop="touchOffType">
              <el-select v-model="addForm.touchOffType" class="otherWidth" placeholder="请选择触发类型">
                <!--  @change="activityTypeChange(addForm.touchOffType)" -->
                <el-option label="出单" value="1"></el-option>
                <el-option label="推广" value="2"></el-option>
                <el-option label="分享" value="3"></el-option>
                <!-- <el-option label="抽奖推广" value="4"></el-option> -->
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="抽奖次数:" prop="drawTimes">
              <el-input v-model="addForm.drawTimes" style="width:100%;" auto-complete="off" placeholder="请输入抽奖次数">
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="宝豆最大倍数:" prop="maxTimes">
              <el-input v-model="addForm.maxTimes" style="width:100%;" auto-complete="off" placeholder="请输入宝豆最大倍数">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="宝豆最小值:" prop="minValue">
              <el-input v-model="addForm.minValue" style="width:100%;" auto-complete="off" placeholder="请输入宝豆最小值">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="宝豆最大值:" prop="drawTimes">
              <el-input v-model="addForm.amountLimitation" style="width:100%;" auto-complete="off" placeholder="请输入宝豆最大值">
              </el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="特殊宝豆:" prop="specialValue">
              <el-input v-model="addForm.specialValue" style="width:100%;" auto-complete="off" placeholder="请输入特殊宝豆">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="特殊宝豆个数:" prop="specialTimes">
              <el-input v-model="addForm.specialTimes" style="width:100%;" auto-complete="off" placeholder="请输入特殊宝豆个数">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="抽奖保费最高比例:" prop="policyRate">
              <el-input v-model="addForm.policyRate" style="width:100%;" auto-complete="off" placeholder="请输入抽奖保费最高比例">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="24" :lg="24">
            <el-form-item label="活动机构:" prop="branchCode" :rules="[
      { required: true, message: '活动机构不能为空'},
    ]">
              <el-select style="width:100%;" multiple v-model="addForm.branchCode" placeholder="请选择活动机构(可多选)">
                <el-option v-for="(item,index) in barchCodes" :key="index" :label="item.codeCname" :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="活动起日期:" prop="planStartTime">
              <el-date-picker type="date" style="width:100%;" placeholder="请选择活动起日期" v-model="addForm.planStartTime" :picker-options="pickerOptions0"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="活动止日期:" prop="planEndTime">
              <el-date-picker type="date" style="width:100%;" placeholder="请选择活动止日期" v-model="addForm.planEndTime" :picker-options="pickerOptions0"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="活动预算:" prop="sumBudget">
              <el-input v-model="addForm.sumBudget" style="width:100%;" auto-complete="off" placeholder="请输入活动预算">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="预警余额:" prop="warnBalance">
              <el-input v-model="addForm.warnBalance" style="width:100%;" auto-complete="off" placeholder="请输入预警余额">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="预警手机:" prop="warnPhoneNo">
              <el-input v-model="addForm.warnPhoneNo" style="width:100%;" auto-complete="off" placeholder="请输入预警手机">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="18" :md="12" :lg="12">
            <el-form-item label="预警邮箱:" prop="warnEmail">
              <el-input v-model="addForm.warnEmail" style="width:100%;" auto-complete="off" placeholder="请输入预警邮箱">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="24" :lg="24">
            <el-form-item label="发放脚本:" prop="activityScript">
              <!-- <el-upload
                        ref="upload"
                        :action="picURL"
                        :on-change="Isupload"
                        :on-success="handleSuccess"
                        :file-list="fileList"
                        :auto-upload="false"
                        :data="{parampath:activityvalue}">
                        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
                      </el-upload> -->
              <el-input v-model="addForm.activityScript" style="width:100%;" auto-complete="off" placeholder="请输入发放脚本">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="活动说明:" prop="remark">
          <el-input type="textarea" :rows="3" v-model="addForm.remark" auto-complete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
      </div>
    </el-dialog>

    <!--详情界面-->
    <el-dialog :title="titles" v-model="detailFormVisible" :close-on-click-modal="false">
      <el-form :model="detailForm" label-width="100px" ref="detailForm">
        <!-- :rules="detailRules" -->
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">活动ID:</label>
            <span class="examineFonts">{{detailForm.id}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">

            <label class="detailLabel">活动状态:</label>
            <span class="examineFonts">{{detailForm.status}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">活动预算:</label>
            <span class="examineFonts">{{detailForm.sumBudget}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">

            <label class="detailLabel">活动余额:</label>
            <span class="examineFonts">{{detailForm.balanceBudget}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">活动名称:</label>
            <span class="examineFonts">{{detailForm.activityName}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">活动编码:</label>
            <span class="examineFonts">{{detailForm.activityCode}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">活动类型:</label>
            <span class="examineFonts">{{detailForm.activityType}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">触发类型:</label>
            <span class="examineFonts">{{detailForm.touchOffType}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" class="detaillabel">
            <label class="detailLabel" style="position:absolute;">活动机构:</label>
            <span class="examineFonts" style="display:inline-block;padding-left:123px;">{{detailForm.branchCode}}</span>
          </el-col>
        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">抽奖次数:</label>
            <span class="examineFonts">{{detailForm.drawTimes}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">剩余次数:</label>
            <span class="examineFonts">{{detailForm.drawBalance}}</span>
          </el-col>
        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">宝豆最小值:</label>
            <span class="examineFonts">{{detailForm.minValue}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">宝豆最大值:</label>
            <span class="examineFonts">{{detailForm.amountLimitation}}</span>
          </el-col>
        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">奖金最大倍数:</label>
            <span class="examineFonts">{{detailForm.maxTimes}}</span>
          </el-col>
        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">特殊宝豆个数:</label>
            <span class="examineFonts">{{detailForm.specialTimes}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">特殊宝豆:</label>
            <span class="examineFonts">{{detailForm.specialValue}}</span>
          </el-col>
        </el-row>
        <el-row v-show="IsactivityType">
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">抽奖保费最高比例:</label>
            <span class="examineFonts">{{detailForm.policyRate}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">计划开始日期:</label>
            <span class="examineFonts">{{detailForm.planStartTime}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">计划结束日期:</label>
            <span class="examineFonts">{{detailForm.planEndTime}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">实际开始日期:</label>
            <span class="examineFonts">{{detailForm.actualStartTime}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">实际结束日期:</label>
            <span class="examineFonts">{{detailForm.actualEndTime}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">活动申请人:</label>
            <span class="examineFonts">{{detailForm.applyer}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">活动申请时间:</label>
            <span class="examineFonts">{{detailForm.applyTime}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">活动审批人:</label>
            <span class="examineFonts">{{detailForm.approver}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">

            <label class="detailLabel">活动审批时间:</label>
            <span class="examineFonts">{{detailForm.approveTime}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">停止申请人:</label>
            <span class="examineFonts">{{detailForm.stopApplyer}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">

            <label class="detailLabel">停止申请时间:</label>
            <span class="examineFonts">{{detailForm.stopApplyTime}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">停止审批人:</label>
            <span class="examineFonts">{{detailForm.stopApprover}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" style="margin-bottom:20px;">

            <label class="detailLabel">停止审批时间:</label>
            <span class="examineFonts">{{detailForm.stopApproveTime}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" style="margin-bottom:20px;">
            <label class="detailLabel">活动说明:</label>
            <span class="examineFonts">{{detailForm.remark}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" style="margin-bottom:20px;">
            <label class="detailLabel" style="position:absolute;">发放脚本:</label>
            <span class="examineFonts" style="display:inline-block;padding-left:123px;">{{detailForm.activityScript}}</span>

          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">预警余额:</label>
            <span class="examineFonts">{{detailForm.warnBalance}}</span>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" class="detaillabel">
            <label class="detailLabel">预警手机:</label>
            <span class="examineFonts">{{detailForm.warnPhoneNo}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" style="margin-bottom:20px;">
            <label class="detailLabel">预警邮箱:</label>
            <span class="examineFonts">{{detailForm.warnEmail}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" v-show="IsInquiry">
            <label class="detailLabel"></label>
            <el-button size="small" type="primary" @click="getbudget">预算添加记录</el-button>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" v-show="IsInquiry">
            <label class="detailLabel"></label>
            <el-button size="small" type="warning" @click="getExamine">审批记录</el-button>
          </el-col>
        </el-row>
        <el-row style="margin-top:10px;">

        </el-row>
        <!-- <el-row> -->
        <!--  <el-col :xs="24" :sm="24" :md="12" :lg="12">
              <label class="detailLabel">发放脚本:</label>
              <el-button size="small" type="warning"  @click="download(detailForm.activityScript)">下载</el-button>
            </el-col> -->

        <!-- </el-row> -->
        <el-row v-show="IsAddExaminebudget">
          <el-col style="margin-top:20px;">
            <div>
              <label class="detailLabel">添加预算:</label>
              <span style="background-color:yellow;" class="examineFonts">{{addBugetData.budget}}</span>
            </div>
          </el-col>
        </el-row>
        <el-row v-show="IsDrawExamine">
          <el-col style="margin-top:20px;">
            <div>
              <label class="detailLabel">添加特殊金额个数:</label>
              <span style="background-color:yellow;" class="examineFonts">{{addBugetData.addSpecialTimes}}</span>
            </div>
          </el-col>
        </el-row>
        <el-row v-show="IsDrawExamine">
          <el-col style="margin-top:20px;">
            <div>
              <label class="detailLabel">添加的抽奖次数:</label>
              <span style="background-color:yellow;" class="examineFonts">{{addBugetData.addDrawTimes}}</span>
            </div>
          </el-col>
        </el-row>
        <!-- </el-form>
      <el-form :model="addBugetData" label-width="100px" :rules="detailRules" ref="addBugetData"> -->
        <el-row v-show="IsAddbudget">
          <el-col style="margin-top:20px;margin-left:30px" :xs="24" :sm="24" :md="24" :lg="24">
            <el-form-item label="活动预算:" prop="budget">
              <!-- :rules="{
      required: true, message: '域名不能为空', trigger: 'blur'
    }" -->
              <input class="addinput" v-model="addBugetData.budget" :readonly="readonlys" style="width:50%;" placeholder="请输入添加的预算" />
              <!-- </el-form-item> -->
            </el-form-item>
          </el-col>
        </el-row>

        <el-row v-show="IsDraw">
          <el-col style="margin-top:20px;margin-left:30px" :xs="24" :sm="24" :md="24" :lg="24">
            <el-form-item label="抽奖次数:" prop="addDrawTimes">
              <input class="addinput" v-model="addBugetData.addDrawTimes" :readonly="readonlys" style="width:50%;" placeholder="请输入添加抽奖次数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="IsDraw">
          <el-col style="margin-top:20px;margin-left:30px" :xs="24" :sm="24" :md="24" :lg="24">
            <!-- <label class="detailLabel" style="display:inline-block;">添加特殊金额个数:</label>
            <input class="addinput" v-model="addBugetData.addSpecialTimes" :readonly="readonlys" style="width:50%;" placeholder="请输入添加特殊金额个数" /> -->
            <el-form-item label="特殊金额个数:" prop="addSpecialTimes">
              <input class="addinput" v-model="addBugetData.addSpecialTimes" :readonly="readonlys" style="width:50%;" placeholder="请输入添加特殊金额个数" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" v-show="IsSubmit" @click.native="submit(submitStatus)" :loading="detailLoading">{{submits}}</el-button>
        <el-button @click.native="cancel(cancelStatus)">{{cancels}}</el-button>
      </div>
    </el-dialog>
    <!-- 查询添加预算  -->
    <el-dialog title="预算添加记录" size="large" v-model="record" :close-on-click-modal="false">
      <el-row>
        <!-- <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
          <el-form :inline="true" :model="recordfilters">
            <el-form-item>
              <el-date-picker
                v-model.trim="recordfilters.Time"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button size="small" icon="search" type="primary" v-on:click="getRecord()">查询</el-button>
            </el-form-item>
          </el-form>
        </el-col> -->
        <el-table :data="recorddata" border :height="winHeight-350" v-loading="recordLoading" highlight-current-row style="width: 100%;">
          <el-table-column prop="approveId" width="120" align="center" label="审批ID">
          </el-table-column>
          <el-table-column prop="userId" align="center" label="用户ID" min-width="130">
          </el-table-column>
          <el-table-column prop="applyUser" label="申请人" align="center" width="120">
          </el-table-column>
          <el-table-column prop="applyTime" label="申请时间" align="center" min-width="140" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="approveTime" label="审批时间" align="center" min-width="140" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="content" width="120" align="center" label="添加预算">
          </el-table-column>
          <!-- <el-table-column prop="remark" min-width="100" align="center" label="备注" show-overflow-tooltip>
          </el-table-column> -->
        </el-table>
        <!--工具条-->
        <el-col :span="24" class="toolbar">
          <el-pagination style="float:right" @size-change="handleSizerecord" @current-change="handleCurrentexrecord" :current-page="recordpage" :page-sizes="[10, 20, 40, 80]" :page-size="recordpageSize" layout="total, sizes, prev, pager, next, jumper" :total="recordtotal">
          </el-pagination>
        </el-col>
      </el-row>
    </el-dialog>
    <!-- 审批记录  -->
    <el-dialog title="审批记录" size="large" v-model="examineDialog" :close-on-click-modal="false">
      <el-row>
        <el-table :data="examines" border height="300" v-loading="examineLoading" highlight-current-row>
          <el-table-column prop="approveId" width="120" align="center" label="审批ID">
          </el-table-column>
          <el-table-column prop="userId" align="center" label="审批人" width="120" sortable>
          </el-table-column>
          <el-table-column prop="applyUser" align="center" label="申请人" width="120" sortable>
          </el-table-column>
          <el-table-column prop="status" align="center" label="状态" width="120" :formatter="formatApplyStatus" sortable>
          </el-table-column>
          <el-table-column prop="type" align="center" label="类型" width="120" :formatter="formatType" sortable>
          </el-table-column>
          <el-table-column prop="approveTime" align="center" label="审批时间" sortable>
          </el-table-column>
          <el-table-column prop="applyTime" align="center" label="申请时间" sortable>
          </el-table-column>
          <!-- <el-table-column label="操作" fixed='right' width="80">
            <template scope="scope">
              <el-button size="small" @click="handleExamine(scope.$index, scope.row)">详情</el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <el-col :span="24" class="toolbar">
          <el-pagination style="float:right" @size-change="handleSizeChanges" @current-change="handleCurrentChanges" :current-page="Examinepage" :page-sizes="[10, 20, 40, 80]" :page-size="ExaminepageSize" layout="total, sizes, prev, pager, next, jumper" :total="Examinetotal">
          </el-pagination>
        </el-col>
      </el-row>
    </el-dialog>
  </section>
</template>

<script>
import util from '../../common/js/util'

import commons from '../../common/js/common'
//import NProgress from 'nprogress'
import { mapState, mapActions } from 'vuex'
import { activityList, issueActivity, stopActivity, addBudget, approveActivity, budgetHis, picURL, base } from '../../api/api';

export default {
  data() {
    var phone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('预警手机不能为空'));
      }
      else {
        if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(value))) {
          callback(new Error('请输入正确的手机号码'));
        }
        else {
          callback();
        }
      }
    };

    var Email = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('预警邮箱不能为空'));
      }
      else {
        if (!(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(value))) {
          callback(new Error('请输入正确的邮箱'));
        }
        else {
          callback();
        }
      }
    };

    var branchCode = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('活动机构不能为空'));
      }
      else {
        if (value) {
        }
        else {
          callback();
        }

      }
    };

    var planStartTime = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('活动起日期不能为空'));
      }
      else {
        callback();
      }
    };

    var planEndTime = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('活动止日期不能为空'));
      }
      else {
        callback();
      }
    };
    var sumBudget = (rule, value, callback) => {

      if (!value) {
        return callback(new Error('活动预算不能为空'));
      }
      else {
        if (!(/^[1-9]\d*$/.test(value))) {
          return callback(new Error('活动预算必须为正整数'));
        }
        else {
          callback();
        }
      }
    };
    var drawTimess = (rule, value, callback) => {
      if (this.addForm.activityType == '3') {
        if (!value) {
          return callback(new Error('抽奖次数不能为空'));
        }
        else {
          if (!(/^[0-9]\d*$/.test(value))) {
            return callback(new Error('抽奖次数必须为正整数'));
          }
          else {
            callback();
          }
        }
      } else {
        callback();
      }
    };
    var minValues = (rule, value, callback) => {
      if (this.addForm.activityType == '3') {
        if (!value) {
          return callback(new Error('个数不能为空'));
        }
        else {
          if (!(/^[1-9]\d*$/.test(value))) {
            return callback(new Error('必须为正整数'));
          }
          else {
            callback();
          }
        }
      } else {
        callback();
      }
    };
    var specialValues = (rule, value, callback) => {
      if (this.addForm.activityType == '3') {
        if (!value) {
          return callback(new Error('个数不能为空'));
        }
        else {
          if (!(/^[0-9]\d*$/.test(value))) {
            return callback(new Error('必须为正整数'));
          }
          // [0-9]\d*   ^-?\\d+$   ^(0|[1-9][0-9]*|-[1-9][0-9]*)$
          else {
            callback();
          }
        }
      } else {
        callback();
      }
    };
    var policyRateVal = (rule, value, callback) => {
      if (this.addForm.activityType == '3') {
        if (!value) {
          return callback(new Error('不能为空'));
        }
        else {
          if (!(/^[0](\.\d{1,2})?$/.test(value)) ) {
            return callback(new Error('必须为0-1之间的小数'));
          }
          else {
            callback();
          }
        }
      } else {
        callback();
      }
    };
    var addBudgetRules = (rule, value, callback) => {
      // if (this.addForm.activityType == '3') {
      if (!value) {
        return callback(new Error('个数不能为空'));
      }
      else {
        if (!(/^[0-9]\d*$/.test(value))) {
          return callback(new Error('必须为正整数'));
        }
        else {
          callback();
        }
      }
      // } else {
      //   callback();
      // }
    };
    var warnBalance = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('预警余额不能为空'));
      }
      else {
        if (!(/^[1-9]\d*$/.test(value))) {
          return callback(new Error('预警余额必须为正整数'));
        }
        else {
          callback();
        }
      }
    };
    return {
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      filters: {
        activityCode: '',
        activityName: '',
        planTime: '',
        status: ''
      },
      recordfilters: {
        Time: ''
      },
      picURL: picURL,
      base: base,
      Logs: [],
      recorddata: [],
      lists: [],
      barchCodes: [],
      fileList: [],
      examines: [],
      exportTotal: 0,
      total: 0,
      page: 1,
      pageSize: 10,
      recordtotal: 0,
      recordpage: 1,
      recordpageSize: 10,
      Examinepage: 1,
      ExaminepageSize: 10,
      Examinetotal: 0,
      loading: '',
      activityvalue: '',
      Isuploads: false,
      // fullscreenLoading:false,
      IsactivityType: false,//抽奖次数显示
      addFormVisible: false,//新增界面是否显示
      detailFormVisible: false,
      examineDialog: false,//审批记录是否显示
      examineLoading: false,
      listLoading: false,
      detailLoading: false,
      addLoading: false,
      recordLoading: false,
      record: false,
      sels: [],//列表选中列
      minRequired: false,
      activityAdd: false,
      activityBudget: false,
      activityDetail: false,
      activityQuery: false,
      activityStop: false,
      activityApprove: false,

      addFormRules: {
        activityName: [
          { required: true, message: '请输入活动名称', trigger: 'blur' }
        ],
        activityType: [
          { required: true, message: '请选择活动类型', trigger: 'blur' }
        ],
        planStartTime: [
          { required: true, validator: planStartTime, trigger: 'blur' }
        ],
        planEndTime: [
          { required: true, validator: planEndTime, trigger: 'blur' }
        ],
        sumBudget: [
          { required: true, validator: sumBudget, trigger: 'blur' }
        ],
        warnBalance: [
          { required: true, validator: warnBalance, trigger: 'blur' }
        ],
        warnPhoneNo: [
          { required: true, validator: phone, trigger: 'blur' }
        ],
        warnEmail: [
          { required: true, validator: Email, trigger: 'blur' }
        ],
        activityScript: [
          { required: true, message: '请输入发放脚本', trigger: 'blur' }
        ],
        drawTimes: [
          { required: this.minRequired, validator: drawTimess, trigger: 'blur' }
        ],
        minValue: [
          { required: this.minRequired, validator: specialValues, trigger: 'blur' }
        ],
        maxTimes: [
          { required: this.minRequired, validator: specialValues, trigger: 'blur' }
        ],
        amountLimitation: [
          { required: this.minRequired, validator: specialValues, trigger: 'blur' }
        ],
        specialValue: [
          { required: this.minRequired, validator: specialValues, trigger: 'blur' }
        ],
        specialTimes: [
          { required: this.minRequired, validator: specialValues, trigger: 'blur' }
        ],
        policyRate: [
          { required: this.minRequired, validator: policyRateVal, trigger: 'blur' }
        ]
      },
      userid: '',
      IsShow: false,
      addForm: {
        activityName: '',
        activityType: '',
        touchOffType: '',
        drawTimes: '',
        branchCode: [],
        planStartTime: '',
        planEndTime: '',
        sumBudget: '',
        warnBalance: '',
        warnPhoneNo: '',
        warnEmail: '',
        activityScript: '',
        remark: '',
        minValue: '',
        maxTimes: '',
        amountLimitation: '',
        specialValue: '',
        specialTimes: '',
        policyRate:''
      },
      detailForm: {
      },
      addBugetData: {
        budget: '',
        addDrawTimes: '',
        addSpecialTimes: '',
        id: ''
      },

      // submit
      IsSubmit: true,//是否显示提交按钮
      IsInquiry: true,//是否显示查询按钮
      IsAddbudget: false,//是否显示添加预算
      IsAddExaminebudget: false,//是否显示添加预算审批
      IsDraw: false,
      IsDrawExamine: false,
      readonlys: false,
      titles: '',
      submits: '提交',
      cancels: '取消',
      submitStatus: '',
      cancelStatus: true
    }
  },
  computed: mapState([
    'user',
    'winWidth',
    'winHeight'
  ]),
  methods: {
    cellStyle(row, rowIndex, columnIndex) {
    },
    formatStatus: function (row, column) {
      return commons.activityStatus(row.status);
    },
    formatTime: function (row, column) {
      return commons.getDaytime(row.createTime, 1, false);
    },
    formatApplyTime: function (row, column) {
      return commons.getDaytime(row.applyTime, 1, false);
    },
    formatApproveTime: function (row, column) {
      return commons.getDaytime(row.approveTime, 1, false);
    },
    formatApplyStatus: function (row, column) {
      return row.status == "0" ? "待审批" : (row.status == "1" ? "通过" : "不通过");
    },
    formatType: function (row, column) {
      return row.type == "4" ? "新增发放审批" : (row.type == "5" ? "停止发放审批" : (row.type == "6" ? "添加预算审批" : ""));
    },
    formatTypes: function (row, column) {
      return commons.activityType(row.activityType);
    },
    //活动类型
    activityTypeChange: function (value) {
      if (value == '3') {
        this.IsactivityType = true;
        this.minRequired = true;
      } else {
        this.IsactivityType = false;
        this.minRequired = false;
      }
      // this.IsactivityType = value == "3" ? true : false;
    },
    //脚本
    handleSuccess(response, file, fileList) {
      this.addForm.activityScript = commons.SuccessUrl(this.addForm.activityScript, file, false);
      this.addrequest();
    },
    Isupload(file, fileList) {
      if (file.status == "ready") {
        this.Isuploads = true;
      }
    },
    // handleRemove(file, fileList) {
    //   this.addForm.imgUrl = commons.RemoveUrl(this.addForm.imgUrl,file);
    // },
    handleCurrentChange(val) {
      this.page = val;
      this.getactive(true);
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getactive(true);
    },
    handleCurrentexrecord(val) {
      this.recordpage = val;
      this.getRecord();
    },
    handleSizerecord(val) {
      this.recordpageSize = val;
      this.getRecord();
    },
    handleCurrentChanges(val) {
      this.Examinepage = val;
      this.getExamineList();
    },
    handleSizeChanges(val) {
      this.ExaminepageSize = val;
      this.getExamineList();
    },
    //获取列表
    getactive(bool) {
      let para = new FormData();
      para.append("pageSize", bool ? this.pageSize : this.exportTotal);
      para.append("pageNumber", bool ? this.page : 1);
      para.append("activityName", this.filters.activityName);
      para.append("activityCode", this.filters.activityCode);
      para.append("status", this.filters.status);
      para.append("planStartTime", commons.changeTimes(this.filters.planTime, 'start'));
      para.append("planEndTime", commons.changeTimes(this.filters.planTime, 'end'));
      this.listLoading = bool;
      // this.fullscreenLoading = bool?false:true;
      if (!bool) {
        this.loading = this.$loading({
          lock: true,
          text: '正在导出',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
      }
      activityList(para).then((res) => {
        this.lists = res.data.result.list;
        this.total = res.data.result.total;
        this.exportTotal = res.data.result.total;
        this.listLoading = false;
        if (!bool) {
          this.loading.close();
          this.export2Excel();
        }
        else {
          this.Logs = res.data.result.list;
        }
      }).catch(() => {
        this.listLoading = false;
      });
    },
    //table导出excel
    exportExcels: function () {
      this.getactive(false);
    },
    export2Excel: function () {
      require.ensure([], () => {
        const { export_json_to_excel } = require('../../vendor/Export2Excel');
        const tHeader = ['分享标识', '分享类型', '产品ID', '业务关系代码', '销售人员', '销售人员编码', '创建用户', '点击次数', '创建时间'];
        const filterVal = ['shareId', 'shareType', 'productId', 'agrementNo', 'saleName', 'saleCode', 'userCode', 'sharinChain', 'createTime'];
        const list = this.lists;
        for (var i in list) {
          list[i].createTime = commons.getDaytime(list[i].createTime, 1, false);
        }
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, '分享列表excel');
      })
    },
    formatJson: function (filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    //审批权限
    ApproveUser(index,row) {
      var approveAuth = row.approveAuth;
      var userArr = this.user.approve;
      return commons.ApproveUser(approveAuth,userArr);
    },
    configUser: function () {
      var userArr = this.user.configAuth;
      return !commons.contains(userArr, '1');
    },
    //显示新增界面
    handleAdd: function () {
      var nowTime = Date.parse(new Date());
      this.addFormVisible = true;
      this.Isuploads = false;
      this.IsactivityType = false;
      this.fileList = [];
      this.addForm = {
        activityName: '',
        activityType: '',
        drawTimes: '',
        branchCode: [],
        planStartTime: '',
        planEndTime: '',
        sumBudget: '',
        warnBalance: '',
        warnPhoneNo: '',
        warnEmail: '',
        activityScript: '',
        remark: '',
        touchOffType: '',
        minValue: '',
        maxTimes: '',
        amountLimitation: '',
        specialValue: '',
        specialTimes: '',
        policyRate:''
      };
      this.activityvalue = 'activity/' + commons.getDaytime(nowTime, 3, false);
    },
    //新增提交
    addSubmit: function () {
      // this.addForm.planStartTime = commons.addHMS(this.addForm.planStartTime);
      // this.addForm.planEndTime = commons.addHMS(this.addForm.planEndTime);
      console.log(this.addForm)
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.addLoading = true;
            // if(this.Isuploads){
            //   this.$refs.upload.submit();
            // }
            // else{
            this.addrequest(this.addForm);
            // }
          });
        }
      });
    },
    //新增请求
    addrequest: function (datas) {
      let para = datas;
      para.planStartTime = (!para.planStartTime || para.planStartTime == '') ? '' : util.formatDate.format(new Date(para.planStartTime), 'yyyy-MM-dd');
      para.planEndTime = (!para.planEndTime || para.planEndTime == '') ? '' : util.formatDate.format(new Date(para.planEndTime), 'yyyy-MM-dd');
      para.branchCode = para.branchCode.join(",");
      issueActivity(para).then((res) => {
        if (res.data.success) {
          this.$message({
            message: '提交成功',
            type: 'success'
          });
          this.$refs['addForm'].resetFields();
          this.addFormVisible = false;
          this.getactive(true);
        }
        else {
          this.$message({
            message: res.data.result,
            type: 'error'
          });
        }
        this.addLoading = false;
      }).catch(() => {
        this.addLoading = false;
      });
    },
    //下载
    download: function (url) {
      var protocol = location.protocol;
      var hostname = location.hostname;
      var sUrl = this.base + url;
      // var $form = $('<form method="GET"></form>');
      // $form.attr('action', protocol+'//'+hostname+url);
      // $form.attr('https://uat-lm.libertymutual.com.cn'+url);
      // $form.appendTo($('body'));
      // $form.submit();
      // window.open('https://uat-lm.libertymutual.com.cn'+url);
      var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
      var isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;

      if (isChrome || isSafari) {
        //Creating new link node.
        var link = document.createElement('a');
        link.href = sUrl;

        if (link.download !== undefined) {
          //Set HTML5 download attribute. This will prevent file from opening if supported.
          var fileName = sUrl.substring(sUrl.lastIndexOf('/') + 1, sUrl.length);
          link.download = fileName;
        }

        //Dispatching click event.
        if (document.createEvent) {
          var e = document.createEvent('MouseEvents');
          e.initEvent('click', true, true);
          link.dispatchEvent(e);
          return true;
        }
      }

      // Force file download (whether supported by server).
      if (sUrl.indexOf('?') === -1) {
        sUrl += '?download';
      }

      window.open(sUrl, '_self');
      return true;
    },
    IsExamineOther: function (index, row) {
      if (this.activityStop) {
        if (row.status == "0" || row.status == "5" || row.status == "6" || row.status == "7") {
          return false;
        }
        else {
          if (row.approve) {
            return false;
          }
          else {
            return true;
          }
        }
      } else {
        return false;
      }
    },
    IsExamineOtherE: function (index, row) {
      if (this.activityBudget) {
        if (row.status == "0" || row.status == "5" || row.status == "6" || row.status == "7") {
          return false;
        }
        else {
          if (row.approve) {
            return false;
          }
          else {
            return true;
          }
        }
      } else {
        return false;
      }
    },
    //是否显示审批
    IsExamines: function (index, row) {
      if (this.activityApprove) {
        return row.approve ? true : false;
      } else {
        return false;
      }
    },

    //详情
    handleDetail: function (index, row) {
      let branchCode = [];
      let branchCodes = [];
      this.detailFormVisible = true;
      this.IsSubmit = false;
      this.IsInquiry = true;
      this.IsAddExaminebudget = false;
      this.IsDrawExamine = false;
      this.IsAddbudget = false;
      this.cancelStatus = true;
      this.titles = "活动发放规则详情";
      this.cancels = "取消";
      this.IsDraw = false;
      this.detailForm = Object.assign({}, row);
      if (row.branchCode) {
        branchCode = row.branchCode.split(',');
        for (var i in branchCode) {
          branchCodes.push(commons.CodeName(this.$store.state.branchCodelist, branchCode[i], 'BranchCode'));
        }
        this.detailForm.branchCode = branchCodes.join(',');
      }
      this.detailForm.status = commons.activityStatus(row.status);
      // this.detailForm.applyTime = commons.getDaytime(row.applyTime, 1, false);
      this.detailForm.activityType = commons.activityType(row.activityType);
      this.detailForm.touchOffType = this.detailForm.touchOffType == '1' ? '出单' : (this.detailForm.touchOffType == '2' ? '推广' : '分享');
      this.IsactivityType = row.activityType == "3" ? true : false;

    },
    //停止
    handleStop: function (index, row) {
      let branchCode = [];
      let branchCodes = [];
      this.detailForm = Object.assign({}, row);
      this.detailFormVisible = true;
      this.IsInquiry = false;
      this.IsSubmit = true;
      this.IsAddbudget = false;
      this.cancelStatus = true;
      this.IsAddExaminebudget = false;
      this.titles = "停止活动发放规则";
      // this.submits = ""
      this.submitStatus = "stop";
      this.submits = "停止";
      this.cancels = "取消";
      if (row.branchCode) {
        branchCode = row.branchCode.split(',');
        for (var i in branchCode) {
          branchCodes.push(commons.CodeName(this.$store.state.branchCodelist, branchCode[i], 'BranchCode'));
        }
        this.detailForm.branchCode = branchCodes.join(',');
      }
      this.detailForm.status = commons.activityStatus(row.status);
      // this.detailForm.applyTime = commons.getDaytime(row.applyTime, 1, false);
      this.detailForm.activityType = commons.activityType(row.activityType);
      this.detailForm.touchOffType = this.detailForm.touchOffType == '1' ? '出单' : (this.detailForm.touchOffType == '2' ? '推广' : '分享');
      this.IsactivityType = row.activityType == "3" ? true : false;
    },
    //添加预算
    handleAddbudget: function (index, row) {
      let branchCode = [];
      let branchCodes = [];
      this.detailForm = Object.assign({}, row);
      this.detailFormVisible = true;
      this.budget = "";
      this.addDrawTimes = '';
      this.addSpecialTimes = '';
      this.readonlys = false;
      this.IsInquiry = false;
      this.cancelStatus = true;
      this.IsSubmit = true;
      this.IsAddExaminebudget = false;
      this.titles = "添加活动预算";
      this.submits = "提交";
      this.cancels = "取消";
      this.IsAddbudget = true;
      this.submitStatus = "addbudget";
      // this.cancelsBudget();
      this.IsDrawExamine = false;
      this.addBugetData = {};
      if (this.detailForm.activityType == '3') {
        this.IsDraw = true;
      } else {
        this.IsDraw = false;
      }
      if (row.branchCode) {
        branchCode = row.branchCode.split(',');
        for (var i in branchCode) {
          branchCodes.push(commons.CodeName(this.$store.state.branchCodelist, branchCode[i], 'BranchCode'));
        }
        this.detailForm.branchCode = branchCodes.join(',');
      }
      this.detailForm.status = commons.activityStatus(row.status);
      // this.detailForm.applyTime = commons.getDaytime(row.applyTime, 1, false);
      this.detailForm.activityType = commons.activityType(row.activityType);
      this.detailForm.touchOffType = this.detailForm.touchOffType == '1' ? '出单' : (this.detailForm.touchOffType == '2' ? '推广' : '分享');
      this.IsactivityType = row.activityType == "3" ? true : false;
    },
    //提交
    submit: function (status) {
      let _this = this;
      let para = new FormData();
      function submitdDetail(fun) {
        _this.$confirm('确认提交吗？', '提示', {}).then(() => {
          _this.detailLoading = true;
          // let para = this.addForm;
          fun(para).then((res) => {
            if (res.data.success) {
              _this.$message({
                message: '提交成功',
                type: 'success'
              });
              // _this.$refs['addForm'].resetFields();
              _this.detailFormVisible = false;
              _this.getactive(true);
            }
            else {
              _this.$message({
                message: res.data.result,
                type: 'error'
              });
            }
            _this.detailLoading = false;
            //NProgress.done();

          }).catch(() => {
            _this.detailLoading = false;
          });
        });
      };
      if (status == "stop") {
        para.append("id", this.detailForm.id);
        submitdDetail(stopActivity);
      }
      else if (status == "addbudget") {
        para.append("id", this.detailForm.id);
        this.addBugetData.id = this.detailForm.id;
        // para = this.addBugetData;
        if (this.addBugetData.budget == "" || this.addBugetData.budget == null) {
          this.$message({
            message: "添加预算不能为空",
            type: 'warning'
          });
        }
        else if (!(/^(0|[1-9][0-9]*|-[1-9][0-9]*)$/.test(this.addBugetData.budget))) {
          this.$message({
            message: "添加预算必须为整数",
            type: 'warning'
          });
        }
        if (this.detailForm.activityType == '3') {

          if (this.addBugetData.addDrawTimes == "" || this.addBugetData.addDrawTimes == null) {
            this.$message({
              message: "添加抽奖次数不能为空",
              type: 'warning'
            });
          }
          else if (!(/^(0|[1-9][0-9]*|-[1-9][0-9]*)$/.test(this.addBugetData.addDrawTimes))) {
            this.$message({
              message: "添加抽奖次数必须为整数",
              type: 'warning'
            });
          }
          else if (this.addBugetData.addSpecialTimes == "" || this.addBugetData.addSpecialTimes == null) {
            this.$message({
              message: "添加特殊金额个数不能为空",
              type: 'warning'
            });
          }
          else if (!(/^(0|[1-9][0-9]*|-[1-9][0-9]*)$/.test(this.addBugetData.addSpecialTimes))) {
            this.$message({
              message: "添加特殊金额个数必须为整数",
              type: 'warning'
            });
          }
        }
        else {
          addBudget(this.addBugetData).then((res) => {
            if (res.data.success) {
              _this.$message({
                message: '提交成功',
                type: 'success'
              });
              _this.detailFormVisible = false;
              _this.getactive(true);
            }
            else {
              _this.$message({
                message: res.data.result,
                type: 'error'
              });
            }
          });
        }

      }
      else if (status == "examineGive") {
        para.append("id", this.detailForm.id);
        para.append("approveType", "4");
        para.append("type", "yes");
        para.append("remark", "");
        submitdDetail(approveActivity);
      }
      else if (status == "examineStop") {
        para.append("id", this.detailForm.id);
        para.append("approveType", "5");
        para.append("type", "yes");
        para.append("remark", "");
        submitdDetail(approveActivity);
      }
      else if (status == "examineAdd") {
        para.append("id", this.detailForm.id);
        para.append("approveType", "6");
        para.append("type", "yes");
        para.append("remark", "");
        submitdDetail(approveActivity);
      }

    },
    //取消
    cancel: function (status) {
      let para = new FormData();
      if (status) {
        this.detailFormVisible = false;
      }
      else {

        if (this.submitStatus == "examineGive") {
          para.append("id", this.detailForm.id);
          para.append("approveType", "4");
          para.append("type", "no");
          para.append("remark", "");
        }
        else if (this.submitStatus == "examineStop") {
          para.append("id", this.detailForm.id);
          para.append("approveType", "5");
          para.append("type", "no");
          para.append("remark", "");
        }
        else if (this.submitStatus == "examineAdd") {
          para.append("id", this.detailForm.id);
          para.append("approveType", "6");
          para.append("type", "no");
          para.append("remark", "");
        }
        this.$confirm('确认拒绝吗？', '提示', {}).then(() => {
          this.detailLoading = true;
          // let para = this.addForm;
          approveActivity(para).then((res) => {
            if (res.data.success) {
              this.$message({
                message: '提交成功',
                type: 'success'
              });
              this.detailFormVisible = false;
              this.getactive(true);
            }
            else {
              this.$message({
                message: res.data.result,
                type: 'error'
              });
            }
            this.detailLoading = false;
            //NProgress.done();

          }).catch(() => {
            this.detailLoading = false;
          });
        });

      }
    },
    //审批
    handleExamine: function (index, row) {
      let branchCode = [];
      let branchCodes = [];
      this.detailFormVisible = true;
      this.IsSubmit = true;
      this.IsInquiry = false;
      this.cancelStatus = false;
      this.IsAddbudget = false;
      this.submits = "同意";
      this.cancels = "拒绝";
      this.IsDraw = false;
      this.detailForm = Object.assign({}, row);
      if (this.addBugetData.addDrawTimes == '' && this.submits == '同意' && this.cancels == '拒绝') {
        this.IsDrawExamine = false;
      } else {
        this.IsDrawExamine = true;
      }
      if (row.branchCode) {
        branchCode = row.branchCode.split(',');
        for (var i in branchCode) {
          branchCodes.push(commons.CodeName(this.$store.state.branchCodelist, branchCode[i], 'BranchCode'));
        }
        this.detailForm.branchCode = branchCodes.join(',');
      }
      this.detailForm.status = commons.activityStatus(row.status);
      // this.detailForm.applyTime = commons.getDaytime(row.applyTime, 1, false);
      this.detailForm.activityType = commons.activityType(row.activityType);
      this.detailForm.touchOffType = this.detailForm.touchOffType == '1' ? '出单' : (this.detailForm.touchOffType == '2' ? '推广' : '分享');
      this.IsactivityType = row.activityType == "3" ? true : false;
      if (row.approve.type == "4") {
        this.titles = "审批活动发放规则";
        this.submitStatus = 'examineGive';
      }
      else if (row.approve.type == "5") {
        this.titles = "审批停止活动发放规则";
        this.submitStatus = 'examineStop';
      }
      else if (row.approve.type == "6") {
        this.titles = "审批添加预算";
        this.submitStatus = 'examineAdd';
        this.readonlys = true;
        this.IsAddExaminebudget = true;
        this.addBugetData = JSON.parse(row.approve.content);

      }
    },
    getbudget: function () {
      this.record = true;
      this.getRecord();
    },
    //添加预算记录查询
    getRecord: function () {
      let para = new FormData();
      para.append("id", this.detailForm.id);
      para.append("pageSize", this.recordpageSize);
      para.append("pageNumber", this.recordpage);
      para.append("type", '6');
      // para.append("startTime",this.recordpage);
      // para.append("endTime",this.recordpage);
      this.recordLoading = true;
      budgetHis(para).then((res) => {
        this.recordLoading = false;
        // this.exclusiveinfmationdata  = res.data.result.content;
        // this.exclusivetotal = res.data.result.totalElements;
        if (res.data.success) {
          this.recorddata = res.data.result.content;
          this.recordtotal = res.data.result.totalElements;
        }
        else {
          this.$message({
            message: res.data.result,
            type: 'error'
          });
        }
      }).catch(() => {
        this.recordLoading = false;
        // this.$message({
        //         message: '数据异常',
        //         type: 'error'
        // });
      });
    },
    //审批记录界面显示
    getExamine: function () {
      this.examineDialog = true;
      this.getExamineList();
    },
    //审批记录列表
    getExamineList: function () {
      let para = new FormData();
      para.append("id", this.detailForm.id);
      para.append("pageSize", this.ExaminepageSize);
      para.append("pageNumber", this.Examinepage);
      para.append("type", 'all');
      // para.append("startTime",this.recordpage);
      // para.append("endTime",this.recordpage);
      this.examineLoading = true;
      budgetHis(para).then((res) => {
        this.examineLoading = false;
        // this.exclusiveinfmationdata  = res.data.result.content;
        // this.exclusivetotal = res.data.result.totalElements;
        if (res.data.success) {
          this.examines = res.data.result.content;
          this.Examinetotal = res.data.result.totalElements;
        }
        else {
          this.$message({
            message: res.data.result,
            type: 'error'
          });
        }
      }).catch(() => {
        this.examineLoading = false;
        // this.$message({
        //         message: '数据异常',
        //         type: 'error'
        // });
      });
    },
    btnShow: function () {
      let thisData = JSON.parse(sessionStorage.getItem('171'));
      let _this = this;
      $.each(thisData, function (i, j) {
        if (thisData[i] == "activityAdd") {
          _this.activityAdd = true;
        }
        if (thisData[i] == "activityBudget") {
          _this.activityBudget = true;
        }
        if (thisData[i] == "activityDetail") {
          _this.activityDetail = true;
        }
        if (thisData[i] == "activityQuery") {
          _this.activityQuery = true;
        }
        if (thisData[i] == "activityStop") {
          _this.activityStop = true;
        }
        if (thisData[i] == "activityApprove") {
          _this.activityApprove = true;
        }
      });
    },
  },
  mounted() {
    this.getactive(true);
    this.btnShow();
    this.barchCodes = this.$store.state.branchCodelist.result;
    // this.barchCodes.push({ "id": "", "codeType": "", "code": "", "codeEname": "111", "codeCname": "总公司", "branchCode": "0000", "validStatus": "1", "serialNo": 1, "remark": null });
  }
}

</script>

<style scoped>
.detailLabel {
  /*float:left;*/
  display: inline-block;
  text-align: right;
  width: 120px;
  color: #0b80da;
  font-weight: bold;
}
.detaillabel {
  margin-bottom: 10px;
}
.addinput {
  display: inline-block;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #bfcbd9;
  box-sizing: border-box;
  color: #1f2d3d;
  font-size: inherit;
  height: 36px;
  line-height: 1;
  outline: 0;
  padding: 3px 10px;
}
.addinput:hover {
  border-color: #20a0ff;
}
</style>